home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / dragon-runner.swf / scripts / PlayerManager.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  10.2 KB  |  369 lines

  1. package
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.events.Event;
  5.    import flash.events.KeyboardEvent;
  6.    
  7.    public class PlayerManager extends Sprite
  8.    {
  9.        
  10.       
  11.       private var ┬º\x01\x01\x02\t┬º:* = null;
  12.       
  13.       internal const PLAYERINITY:* = 337;
  14.       
  15.       internal const RIGHT:* = 2;
  16.       
  17.       internal const BTATTACK:* = 65;
  18.       
  19.       internal const OUTSCR:* = 999;
  20.       
  21.       private var ┬º\x01\x01\x02\r┬º:* = null;
  22.       
  23.       internal const LEFT:* = 1;
  24.       
  25.       public var scoreMgr:* = null;
  26.       
  27.       internal const DOC_HEIGHT:* = 400;
  28.       
  29.       internal const LIMITLOWER:* = 337;
  30.       
  31.       internal const PLAYERHEIGHT:* = 85;
  32.       
  33.       internal const JUMP:* = 11;
  34.       
  35.       internal const ATTACK:* = 21;
  36.       
  37.       internal const BTBLOCK:* = 83;
  38.       
  39.       private var ┬º\x01\x01\b\x05┬º:Boolean;
  40.       
  41.       internal const BTLEFT:* = 37;
  42.       
  43.       internal const PLAYERWIDTH:* = 80;
  44.       
  45.       public var theKnight:* = null;
  46.       
  47.       private var ┬º\x01\x01\x06\r┬º:* = null;
  48.       
  49.       internal const BLOCK:* = 22;
  50.       
  51.       internal const CENTER:* = 3;
  52.       
  53.       internal const DEAD:* = 666;
  54.       
  55.       internal const DOC_TOP:* = 0;
  56.       
  57.       internal const BTJUMP:* = 38;
  58.       
  59.       private var ┬º\x01\x01\b\x07┬º:Boolean;
  60.       
  61.       internal const DOWN:* = 12;
  62.       
  63.       internal const STAND:* = 0;
  64.       
  65.       private var ┬º\x01\x01\x04\x0e┬º:Boolean = false;
  66.       
  67.       internal const BTJUMPATTACK:* = 68;
  68.       
  69.       internal const DOC_WIDTH:* = 640;
  70.       
  71.       internal const PLAYERINITX:* = DOC_WIDTH + 10;
  72.       
  73.       internal const DOC_LEFT:* = 0;
  74.       
  75.       internal const LIMITUPPER:* = 237;
  76.       
  77.       private var ┬º\x01\x01\b\x0b┬º:int = 0;
  78.       
  79.       private var ┬º\x01\x01\b\r┬º:int = 0;
  80.       
  81.       internal const NORMAL:* = 20;
  82.       
  83.       internal const BTRIGHT:* = 39;
  84.       
  85.       private var ┬º\x01\x01\b\x0e┬º:Boolean = false;
  86.       
  87.       private var ┬º\x01\x01\b\x0f┬º:Boolean;
  88.       
  89.       internal const JUMPATTACK:* = 23;
  90.       
  91.       public function PlayerManager(param1:*, param2:*, param3:*)
  92.       {
  93.          ┬º\x01\x01\x04\x0e┬º = false;
  94.          ┬º\x01\x01\x02\t┬º = null;
  95.          ┬º\x01\x01\x02\r┬º = null;
  96.          scoreMgr = null;
  97.          theKnight = null;
  98.          ┬º\x01\x01\x06\r┬º = null;
  99.          ┬º\x01\x01\b\r┬º = 0;
  100.          ┬º\x01\x01\b\x0e┬º = false;
  101.          ┬º\x01\x01\b\x0b┬º = 0;
  102.          super();
  103.          ┬º\x01\x01\x02\t┬º = param1;
  104.          ┬º\x01\x01\x02\r┬º = param2;
  105.          scoreMgr = param3;
  106.          ┬º\x01\x01\x06\r┬º = ┬º\x01\x01\x02\r┬º.GetSceneContainer();
  107.       }
  108.       
  109.       public function UpdateScore() : *
  110.       {
  111.          scoreMgr.SetHealth(theKnight.Health);
  112.          scoreMgr.SetArmor(theKnight.Armor);
  113.       }
  114.       
  115.       public function GetKnightStatus() : int
  116.       {
  117.          return ┬º\x01\x01\b\r┬º;
  118.       }
  119.       
  120.       public function SetKnightStatus(param1:String) : *
  121.       {
  122.          if(param1 == "stand" || param1 == "normal")
  123.          {
  124.             ┬º\x01\x01\b\f┬º(0);
  125.             ┬º\x01\x01\b\r┬º = NORMAL;
  126.             theKnight.SetFace("run");
  127.          }
  128.          else if(param1 == "right")
  129.          {
  130.             theKnight.Move("right");
  131.          }
  132.          else if(param1 == "left")
  133.          {
  134.             theKnight.Move("left");
  135.          }
  136.          else if(param1 == "center")
  137.          {
  138.             ┬º\x01\x01\b\r┬º = NORMAL;
  139.             theKnight.Move("center");
  140.             if(theKnight.Face != "run")
  141.             {
  142.                theKnight.SetFace("run");
  143.             }
  144.          }
  145.          else if(param1 == "jump")
  146.          {
  147.             if(!┬º\x01\x01\b\x0e┬º && theKnight.Health > 0)
  148.             {
  149.                ┬º\x01\x01\b\f┬º(700);
  150.                ┬º\x01\x01\b\r┬º = JUMP;
  151.                theKnight.Jump();
  152.                if(theKnight.Face != "jump")
  153.                {
  154.                   theKnight.SetFace("jump");
  155.                }
  156.             }
  157.          }
  158.          else if(param1 == "jumpattack")
  159.          {
  160.             if(!┬º\x01\x01\b\x0e┬º && theKnight.Armor > 0 && theKnight.Health > 0)
  161.             {
  162.                ┬º\x01\x01\b\f┬º(700);
  163.                ┬º\x01\x01\b\r┬º = JUMPATTACK;
  164.                theKnight.Jump();
  165.                if(theKnight.Face != "jumpattack")
  166.                {
  167.                   theKnight.SetFace("jumpattack");
  168.                }
  169.             }
  170.          }
  171.          else if(param1 == "attack")
  172.          {
  173.             if(!┬º\x01\x01\b\x0e┬º && theKnight.Armor > 0 && theKnight.Health > 0)
  174.             {
  175.                ┬º\x01\x01\b\f┬º(350);
  176.                ┬º\x01\x01\b\r┬º = ATTACK;
  177.                if(theKnight.Face != "attack")
  178.                {
  179.                   theKnight.SetFace("attack");
  180.                }
  181.             }
  182.          }
  183.          else if(param1 == "block")
  184.          {
  185.             if(!┬º\x01\x01\b\x0e┬º && theKnight.Armor > 0 && theKnight.Health > 0)
  186.             {
  187.                ┬º\x01\x01\b\f┬º(1);
  188.                ┬º\x01\x01\b\r┬º = BLOCK;
  189.                if(theKnight.Face != "block")
  190.                {
  191.                   theKnight.SetFace("block");
  192.                }
  193.             }
  194.          }
  195.          else if(param1 == "out")
  196.          {
  197.             ┬º\x01\x01\b\r┬º = OUTSCR;
  198.          }
  199.       }
  200.       
  201.       public function StopGame() : *
  202.       {
  203.          ┬º\x01\x01\b\b┬º();
  204.          ┬º\x01\x01\x02\t┬º.removeEventListener(KeyboardEvent.KEY_DOWN,┬º\x01\x01\b\x03┬º);
  205.          ┬º\x01\x01\x02\t┬º.removeEventListener(KeyboardEvent.KEY_UP,┬º\x01\x01\b\x04┬º);
  206.          ┬º\x01\x01\x02\t┬º.removeEventListener(Event.ENTER_FRAME,┬º\x01\x01\b\x06┬º);
  207.       }
  208.       
  209.       private function ┬º\x01\x01\b\x03┬º(param1:KeyboardEvent) : *
  210.       {
  211.          if(┬º\x01\x01\b\r┬º != DEAD && ┬º\x01\x01\b\r┬º != OUTSCR)
  212.          {
  213.             switch(param1.keyCode)
  214.             {
  215.                case BTRIGHT:
  216.                   ┬º\x01\x01\b\x0f┬º = true;
  217.                   ┬º\x01\x01\b\x07┬º = false;
  218.                   break;
  219.                case BTLEFT:
  220.                   ┬º\x01\x01\b\x07┬º = true;
  221.                   ┬º\x01\x01\b\x0f┬º = false;
  222.                   break;
  223.                case BTJUMP:
  224.                   if(!┬º\x01\x01\b\x0e┬º)
  225.                   {
  226.                      SetKnightStatus("jump");
  227.                   }
  228.                   break;
  229.                case BTBLOCK:
  230.                   if(!┬º\x01\x01\b\x0e┬º)
  231.                   {
  232.                      ┬º\x01\x01\b\x05┬º = true;
  233.                      SetKnightStatus("block");
  234.                   }
  235.                   break;
  236.                case BTATTACK:
  237.                   if(!┬º\x01\x01\b\x0e┬º)
  238.                   {
  239.                      SetKnightStatus("attack");
  240.                   }
  241.                   break;
  242.                case BTJUMPATTACK:
  243.                   if(!┬º\x01\x01\b\x0e┬º)
  244.                   {
  245.                      SetKnightStatus("jumpattack");
  246.                   }
  247.             }
  248.          }
  249.       }
  250.       
  251.       private function ┬º\x01\x01\b\x04┬º(param1:KeyboardEvent) : *
  252.       {
  253.          switch(param1.keyCode)
  254.          {
  255.             case BTRIGHT:
  256.                ┬º\x01\x01\b\x0f┬º = false;
  257.                break;
  258.             case BTLEFT:
  259.                ┬º\x01\x01\b\x07┬º = false;
  260.                break;
  261.             case BTBLOCK:
  262.                ┬º\x01\x01\b\x05┬º = false;
  263.          }
  264.       }
  265.       
  266.       private function ┬º\x01\x01\b\x06┬º(param1:Event) : *
  267.       {
  268.          if(┬º\x01\x01\b\x0e┬º)
  269.          {
  270.             ┬º\x01\x01\b\n┬º();
  271.          }
  272.          if(┬º\x01\x01\b\x0f┬º)
  273.          {
  274.             SetKnightStatus("right");
  275.          }
  276.          else if(┬º\x01\x01\b\x07┬º)
  277.          {
  278.             SetKnightStatus("left");
  279.          }
  280.          if(!┬º\x01\x01\b\x05┬º)
  281.          {
  282.             if(┬º\x01\x01\b\r┬º == BLOCK)
  283.             {
  284.                SetKnightStatus("normal");
  285.             }
  286.          }
  287.       }
  288.       
  289.       public function StartGame() : *
  290.       {
  291.          ┬º\x01\x01\b\t┬º();
  292.          ┬º\x01\x01\x06\r┬º.stage.focus = ┬º\x01\x01\x02\t┬º;
  293.          ┬º\x01\x01\x02\t┬º.addEventListener(KeyboardEvent.KEY_DOWN,┬º\x01\x01\b\x03┬º,false,0,false);
  294.          ┬º\x01\x01\x02\t┬º.addEventListener(KeyboardEvent.KEY_UP,┬º\x01\x01\b\x04┬º,false,0,true);
  295.          ┬º\x01\x01\x02\t┬º.addEventListener(Event.ENTER_FRAME,┬º\x01\x01\b\x06┬º,false,0,true);
  296.       }
  297.       
  298.       private function ┬º\x01\x01\b\b┬º() : *
  299.       {
  300.          if(theKnight)
  301.          {
  302.             ┬º\x01\x01\x06\r┬º.removeChild(theKnight);
  303.             theKnight.Destroy();
  304.             theKnight = null;
  305.          }
  306.       }
  307.       
  308.       public function GetKnightHealth() : int
  309.       {
  310.          return theKnight.Health;
  311.       }
  312.       
  313.       public function GetKnightArmor() : int
  314.       {
  315.          return theKnight.Armor;
  316.       }
  317.       
  318.       private function ┬º\x01\x01\b\t┬º() : *
  319.       {
  320.          ┬º\x01\x01\b\b┬º();
  321.          theKnight = new knight();
  322.          theKnight.x = PLAYERINITX;
  323.          theKnight.y = PLAYERINITY;
  324.          theKnight.height = PLAYERHEIGHT;
  325.          theKnight.width = PLAYERWIDTH;
  326.          theKnight.Init(┬º\x01\x01\x02\t┬º,┬º\x01\x01\x06\r┬º,this);
  327.          ┬º\x01\x01\b\x07┬º = false;
  328.          ┬º\x01\x01\b\x0f┬º = false;
  329.          ┬º\x01\x01\b\x05┬º = false;
  330.          ┬º\x01\x01\x06\r┬º.addChild(theKnight);
  331.          SetKnightStatus("center");
  332.       }
  333.       
  334.       private function ┬º\x01\x01\b\n┬º() : Boolean
  335.       {
  336.          if(┬º\x01\x01\b\x0b┬º > 0)
  337.          {
  338.             --┬º\x01\x01\b\x0b┬º;
  339.             ┬º\x01\x01\b\x0e┬º = true;
  340.          }
  341.          else
  342.          {
  343.             SetKnightStatus("normal");
  344.             ┬º\x01\x01\b\x0e┬º = false;
  345.          }
  346.          return ┬º\x01\x01\b\x0e┬º;
  347.       }
  348.       
  349.       private function ┬º\x01\x01\b\f┬º(param1:*) : *
  350.       {
  351.          if(param1 == 0)
  352.          {
  353.             ┬º\x01\x01\b\x0e┬º = false;
  354.             ┬º\x01\x01\b\x0b┬º = 0;
  355.          }
  356.          else if(param1 == 1)
  357.          {
  358.             ┬º\x01\x01\b\x0e┬º = true;
  359.             ┬º\x01\x01\b\x0b┬º = 10000;
  360.          }
  361.          else
  362.          {
  363.             ┬º\x01\x01\b\x0b┬º = Math.round(param1 / 42);
  364.             ┬º\x01\x01\b\x0e┬º = true;
  365.          }
  366.       }
  367.    }
  368. }
  369.